home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_11 / phillip2 / overlay.c < prev    next >
C/C++ Source or Header  |  1993-05-22  |  8KB  |  281 lines

  1.  
  2.  
  3.     /***********************************************
  4.     *
  5.     *       file d:\cips\overlay.c
  6.     *
  7.     *       Functions: This file contains
  8.     *          non_zero_overlay
  9.     *          zero_overlay
  10.     *          greater_overlay
  11.     *          less_overlay
  12.     *          average_overlay
  13.     *
  14.     *       Purpose:
  15.     *          These functions implement the functions
  16.     *          that overlay one image on top of another
  17.     *          image.
  18.     *
  19.     *       External Calls:
  20.     *          wtiff.c - create_file_if_needed
  21.     *                    write_array_into_tiff_image
  22.     *          tiff.c - read_tiff_header
  23.     *          rtiff.c - read_tiff_image
  24.     *          numcvrt.c - get_integer
  25.     *
  26.     *       Modifications:
  27.     *          6 March 1993 - created
  28.     *
  29.     ***********************************************/
  30.  
  31.  
  32. #include "cips.h"
  33.  
  34.  
  35.  
  36.    /**************************************************
  37.    *
  38.    *   non_zero_overlay(...
  39.    *
  40.    *   This function overlays in1 on top of in2
  41.    *   and writes the result to the output image.
  42.    *   It writes any non-zero pixel from in1 on top
  43.    *   of in2.
  44.    *
  45.    ***************************************************/
  46.  
  47. non_zero_overlay(in1_name, in2_name, out_name,
  48.           the_image, out_image,
  49.           il1, ie1, ll1, le1,
  50.           il2, ie2, ll2, le2,
  51.           il3, ie3, ll3, le3)
  52.    char   in1_name[], in2_name[], out_name[];
  53.    int    il1, ie1, ll1, le1,
  54.           il2, ie2, ll2, le2,
  55.           il3, ie3, ll3, le3;
  56.    short  the_image[ROWS][COLS],
  57.           out_image[ROWS][COLS];
  58. {
  59.    int    i, j, length, width;
  60.    struct tiff_header_struct image_header;
  61.  
  62.    create_file_if_needed(in1_name, out_name, out_image);
  63.  
  64.    read_tiff_image(in1_name, the_image,
  65.                    il1, ie1, ll1, le1);
  66.    read_tiff_image(in2_name, out_image,
  67.                    il2, ie2, ll2, le2);
  68.  
  69.    for(i=0; i<ROWS; i++){
  70.       if ( (i%10) == 0) printf(" %d", i);
  71.       for(j=0; j<COLS; j++){
  72.          if(the_image[i][j] != 0)
  73.             out_image[i][j] = the_image[i][j];
  74.       }  /* ends loop over j */
  75.    }  /* ends loop over i */
  76.  
  77.    write_array_into_tiff_image(out_name, out_image,
  78.                                il3, ie3, ll3, le3);
  79.  
  80. } /* ends non_zero_overlay */
  81.  
  82.  
  83.  
  84.  
  85.  
  86.    /**************************************************
  87.    *
  88.    *   zero_overlay(...
  89.    *
  90.    *   This function overlays in1 on top of in2
  91.    *   and writes the result to the output image.
  92.    *   It writes any zero pixel from in1 on top
  93.    *   of in2.
  94.    *
  95.    ***************************************************/
  96.  
  97. zero_overlay(in1_name, in2_name, out_name,
  98.          the_image, out_image,
  99.          il1, ie1, ll1, le1,
  100.          il2, ie2, ll2, le2,
  101.          il3, ie3, ll3, le3)
  102.    char  in1_name[], in2_name[], out_name[];
  103.    int   il1, ie1, ll1, le1,
  104.          il2, ie2, ll2, le2,
  105.          il3, ie3, ll3, le3;
  106.    short the_image[ROWS][COLS],
  107.          out_image[ROWS][COLS];
  108. {
  109.    int    i, j, length, width;
  110.    struct tiff_header_struct image_header;
  111.  
  112.    create_file_if_needed(in1_name, out_name, out_image);
  113.  
  114.    read_tiff_image(in1_name, the_image,
  115.                    il1, ie1, ll1, le1);
  116.    read_tiff_image(in2_name, out_image,
  117.                    il2, ie2, ll2, le2);
  118.  
  119.    for(i=0; i<ROWS; i++){
  120.       if ( (i%10) == 0) printf(" %d", i);
  121.       for(j=0; j<COLS; j++){
  122.          if(the_image[i][j] == 0)
  123.             out_image[i][j] = the_image[i][j];
  124.       }  /* ends loop over j */
  125.    }  /* ends loop over i */
  126.  
  127.    write_array_into_tiff_image(out_name, out_image,
  128.                                il3, ie3, ll3, le3);
  129.  
  130. } /* ends zero_overlay */
  131.  
  132.  
  133.  
  134.  
  135.  
  136.    /**************************************************
  137.    *
  138.    *   greater_overlay(...
  139.    *
  140.    *   This function overlays in1 on top of in2
  141.    *   and writes the result to the output image.
  142.    *   It writes in1 on top of in2 if the value of
  143.    *   in1 is greater than in2.
  144.    *
  145.    ***************************************************/
  146.  
  147. greater_overlay(in1_name, in2_name, out_name,
  148.          the_image, out_image,
  149.          il1, ie1, ll1, le1,
  150.          il2, ie2, ll2, le2,
  151.          il3, ie3, ll3, le3)
  152.    char  in1_name[], in2_name[], out_name[];
  153.    int   il1, ie1, ll1, le1,
  154.          il2, ie2, ll2, le2,
  155.          il3, ie3, ll3, le3;
  156.    short the_image[ROWS][COLS],
  157.          out_image[ROWS][COLS];
  158. {
  159.    int    i, j, length, width;
  160.    struct tiff_header_struct image_header;
  161.  
  162.    create_file_if_needed(in1_name, out_name, out_image);
  163.  
  164.    read_tiff_image(in1_name, the_image,
  165.                    il1, ie1, ll1, le1);
  166.    read_tiff_image(in2_name, out_image,
  167.                    il2, ie2, ll2, le2);
  168.  
  169.    for(i=0; i<ROWS; i++){
  170.       if ( (i%10) == 0) printf(" %d", i);
  171.       for(j=0; j<COLS; j++){
  172.          if(the_image[i][j] > out_image[i][j])
  173.             out_image[i][j] = the_image[i][j];
  174.       }  /* ends loop over j */
  175.    }  /* ends loop over i */
  176.  
  177.    write_array_into_tiff_image(out_name, out_image,
  178.                                il3, ie3, ll3, le3);
  179.  
  180. } /* ends greater_overlay */
  181.  
  182.  
  183.  
  184.  
  185.  
  186.    /**************************************************
  187.    *
  188.    *   less_overlay(...
  189.    *
  190.    *   This function overlays in1 on top of in2
  191.    *   and writes the result to the output image.
  192.    *   It writes in1 on top of in2 if the value of
  193.    *   in1 is less than in2.
  194.    *
  195.    ***************************************************/
  196.  
  197. less_overlay(in1_name, in2_name, out_name,
  198.          the_image, out_image,
  199.          il1, ie1, ll1, le1,
  200.          il2, ie2, ll2, le2,
  201.          il3, ie3, ll3, le3)
  202.    char  in1_name[], in2_name[], out_name[];
  203.    int   il1, ie1, ll1, le1,
  204.          il2, ie2, ll2, le2,
  205.          il3, ie3, ll3, le3;
  206.    short the_image[ROWS][COLS],
  207.          out_image[ROWS][COLS];
  208. {
  209.    int    i, j, length, width;
  210.    struct tiff_header_struct image_header;
  211.  
  212.    create_file_if_needed(in1_name, out_name, out_image);
  213.  
  214.    read_tiff_image(in1_name, the_image,
  215.                    il1, ie1, ll1, le1);
  216.    read_tiff_image(in2_name, out_image,
  217.                    il2, ie2, ll2, le2);
  218.  
  219.    for(i=0; i<ROWS; i++){
  220.       if ( (i%10) == 0) printf(" %d", i);
  221.       for(j=0; j<COLS; j++){
  222.          if(the_image[i][j] < out_image[i][j])
  223.             out_image[i][j] = the_image[i][j];
  224.       }  /* ends loop over j */
  225.    }  /* ends loop over i */
  226.  
  227.    write_array_into_tiff_image(out_name, out_image,
  228.                                il3, ie3, ll3, le3);
  229.  
  230. } /* ends less_overlay */
  231.  
  232.  
  233.  
  234.  
  235.  
  236.    /**************************************************
  237.    *
  238.    *   average_overlay(...
  239.    *
  240.    *   This function mixes in1 and in2
  241.    *   and writes the result to the output image.
  242.    *   It writes the average of in1 and in2 to the
  243.    *   output image.
  244.    *
  245.    ***************************************************/
  246.  
  247. average_overlay(in1_name, in2_name, out_name,
  248.          the_image, out_image,
  249.          il1, ie1, ll1, le1,
  250.          il2, ie2, ll2, le2,
  251.          il3, ie3, ll3, le3)
  252.    char  in1_name[], in2_name[], out_name[];
  253.    int   il1, ie1, ll1, le1,
  254.          il2, ie2, ll2, le2,
  255.          il3, ie3, ll3, le3;
  256.    short the_image[ROWS][COLS],
  257.          out_image[ROWS][COLS];
  258. {
  259.    int    i, j, length, width;
  260.    struct tiff_header_struct image_header;
  261.  
  262.    create_file_if_needed(in1_name, out_name, out_image);
  263.  
  264.    read_tiff_image(in1_name, the_image,
  265.                    il1, ie1, ll1, le1);
  266.    read_tiff_image(in2_name, out_image,
  267.                    il2, ie2, ll2, le2);
  268.  
  269.    for(i=0; i<ROWS; i++){
  270.       if ( (i%10) == 0) printf(" %d", i);
  271.       for(j=0; j<COLS; j++){
  272.          out_image[i][j] =
  273.             (the_image[i][j] + out_image[i][j])/2;
  274.       }  /* ends loop over j */
  275.    }  /* ends loop over i */
  276.  
  277.    write_array_into_tiff_image(out_name, out_image,
  278.                                il3, ie3, ll3, le3);
  279.  
  280. } /* ends average_overlay */
  281.